--[[
Description:
Version: 1.0
Autor: zhangchaowei
Date: 2020-12-16 15:24:43
LastEditors: zhangchaowei
LastEditTime: 2022-03-11 15:47:25
--]]

local skynet     = require "skynet"
local mysql      = require "skynet.db.mysql"
local cjson      = require "cjson"
local datacenter = require "skynet.datacenter"
local template   = require "template"
local redis      = require "skynet.db.redis"
local parser     = require "parser"
local keysutils  = require "keysutils"
local mongo      = require "skynet.db.mongo"


require "functions"
require "skynet.manager"

local CMD = {}

local client
local mongodb

skynet.start(function()
    skynet.dispatch("lua", function(session, source, cmd, ...)
        skynet.error("usercenterd dispatch", cmd)
        local f = assert(CMD[cmd])
        skynet.ret(skynet.pack(f(...)))
    end)

    --链接mongo
    local mongoconf = {
        host = MONGO_CONF.ip,
        port = math.tointeger(MONGO_CONF.port),
    }
    client = mongo.client(mongoconf)
    if not client then
        error("mongocenterd mongo 数据库连接失败")
    end

    mongodb = client:getDB(APPNAME)
    if not mongodb then
        error("mongo 连接失败")
    end
    skynet.fork(function()
        while true do
            if true then
                mongodb = client:getDB(APPNAME)
                skynet.sleep(1000)
            end
        end
    end)
    skynet.register "mongod"
end)
